package com.xiaoyy.core.config.set;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @description:
 * @author: chenzh
 * @time: 2020/4/19 19:40
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 系统管理
     * */
    @Bean
    public Docket createSystemRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaoyy.system.manager"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .groupName("系统管理");
    }
    /**
     * 系统通用
     * */
    @Bean
    public Docket createCoreRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaoyy.core"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .groupName("系统通用");
    }
    /**
     * 登录认证
     * */
    @Bean
    public Docket createSSORestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaoyy.sso"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .groupName("登录认证");
    }
    /**
     * app移动端服务
     * */
    @Bean
    public Docket createAppApiRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaoyy.app.api"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .groupName("app服务");
    }
    /**
     * app管理系统服务
     * */
    @Bean
    public Docket createAppManagerRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaoyy.app.manager"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .groupName("app管理系统服务");
    }
    /**
     * api信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口管理系统")
                .description("接口文档")
                .contact(new Contact("chenzh", "", "845078693@qq.com"))
                .version("1.0")
                .build();
    }

}
